#include "drop.h"

Drop::Drop(QWidget *parent) :
    QWidget(parent)
{
    setFixedSize(370,280);
    setAcceptDrops(true);
}

void Drop::dropEvent(QDropEvent *event)
{
    if(event->mimeData()->hasFormat("text/uri-list"))
    {

        QList<QUrl> urls = event->mimeData()->urls();

        foreach(QUrl url, urls)
        {
            emit dropFile(url.path());
        }

    }

}

void Drop::dragEnterEvent(QDragEnterEvent *event)
{
    if(event->mimeData()->hasText())
    {
        if(event->source() == this){
            event->setDropAction(Qt::MoveAction);
            event->accept();
        } else { event->acceptProposedAction(); }

    } else event->ignore();
}

void Drop::paintEvent(QPaintEvent *)
{
    QPainter p(this);

    QPen pen(Qt::SolidPattern,8,Qt::DashLine,Qt::SquareCap,Qt::RoundJoin);
    pen.setColor("darkGray");

    p.setPen(pen);
    p.drawRect(rect());
    p.setFont(QFont("Times", 31));
    p.drawText(rect(),Qt::AlignCenter,"Drop file");
}

